from applications.extensions import db

class UserWechat(db.Model):
    __tablename__ = 'user_wechat'
    __table_args__ = {
        'mysql_engine': 'InnoDB',
        'mysql_charset': 'utf8mb4',
        'mysql_collate': 'utf8mb4_general_ci'
    }

    id = db.Column(db.Integer, primary_key=True, autoincrement=True)
    userid = db.Column(db.Integer, nullable=True, comment='用户ID')
    openid = db.Column(db.String(50), nullable=True, unique=True, comment='用户的唯一标识')
    nickname = db.Column(db.String(50), nullable=True, comment='用户昵称')
    sex = db.Column(db.String(2), nullable=True, comment='用户的性别，值为1时是男性，值为2时是女性，值为0时是未知')
    province = db.Column(db.String(24), nullable=True, comment='用户个人资料填写的省份')
    city = db.Column(db.String(24), nullable=True, comment='普通用户个人资料填写的城市')
    country = db.Column(db.String(24), nullable=True, comment='国家，如中国为CN')
    headimgurl = db.Column(db.String(500), nullable=True, comment='用户头像')
    privilege = db.Column(db.String(150), nullable=True, comment='用户特权信息')
    unionid = db.Column(db.String(50), nullable=True,
                        comment='只有在用户将公众号绑定到微信开放平台账号后，才会出现该字段。')
    regtime = db.Column(db.Integer, nullable=True, comment='激活时间')
    logintime = db.Column(db.Integer, nullable=True, comment='登录时间')
    loginip = db.Column(db.String(24), nullable=True, comment='最后一次登录ip')

    def __repr__(self):
        return f'<UserWechat {self.openid}>'